package com.telit.common.config;

import com.telit.common.aspect.SysLogAspect;
import com.telit.common.listener.SysOperationLogEventLogListener;
import com.telit.common.service.LogService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;


/**
 * 日志自动配置
 * <p>
 * 服务需要实现 LogService 接口，用于保存日志到数据库
 * </p>
 *
 * @author yuezhuang
 * @date 2022-09-19
 */
@EnableAsync
@ConditionalOnWebApplication
@ConditionalOnBean(value = LogService.class)
@Configuration(proxyBeanMethods = false)
public class LogAutoConfiguration {

    /**
     * 操作日志监听
     *
     * @param logService LogService
     *
     * @return SysOperationLogEventLogListener
     */
    @Bean
    public SysOperationLogEventLogListener sysOperationLogEventLogListener(LogService logService) {
        return new SysOperationLogEventLogListener(logService);
    }

    /**
     * 系统操作日志
     *
     * @return SysLogAspect
     */
    @Bean
    public SysLogAspect sysLogAspect() {
        return new SysLogAspect();
    }

}
